from django.db import models

# Create your models here.


# 创建表结构
class Department(models.Model):
    """部门表"""
    title = models.CharField(verbose_name='标题', max_length=32, blank=True, null=True)

    def __str__(self):
        return self.title


class UserInfo(models.Model):
    """员工表"""
    name = models.CharField(verbose_name='姓名', max_length=16)
    password = models.CharField(verbose_name='密码', max_length=64)
    age = models.IntegerField(verbose_name='年龄')
    account = models.DecimalField(verbose_name='账户余额', max_digits=10, decimal_places=2, default=0)
    # creat_time = models.DateTimeField(verbose_name='入职时间')
    creat_time = models.DateField(verbose_name='入职时间')

    # 1. 无约束
    # did = models.BigIntegerField(verbose_name='部门id')
    # 2. 有约束
    #   - to 与哪张表关联
    #   - to_fields 与表中哪一列进行关联
    # 在django中写depart, 在MySQL中生成 depart_id 数据列
    # 部门被删除, 则其部门所属员工
    # - 删除, 级联删除 on_delete=models.CASCADE
    # - 置空 null=True, black=True, on_delete=models.SET_NULL
    depart = models.ForeignKey(verbose_name='部门', to='Department', to_field="id", null=True, blank=True, on_delete=models.CASCADE)

    # 在django中的约束
    gender_cho = (
        (1, '男'),
        (2, '女')
    )
    gender = models.SmallIntegerField(verbose_name='性别', choices=gender_cho)


class PrettyNum(models.Model):
    """靓号表"""
    mobile = models.CharField(verbose_name='手机号', max_length=32)
    # 想要允许为空, null=True, blank=True
    price = models.IntegerField(verbose_name='价格', default=0, null=True, blank=True)

    level_cho = (
        (1, '一级'),
        (2, '二级'),
        (3, '三级'),
        (4, '四级'),
    )
    level = models.SmallIntegerField(verbose_name='级别', choices=level_cho, default=1)

    status_cho = (
        (1, '已占用'),
        (2, '未使用')
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_cho, default=2)


class Admin(models.Model):
    """管理员"""
    user_name = models.CharField(verbose_name='用户名', max_length=12)
    password = models.CharField(verbose_name='密码', max_length=64)

    def __str__(self):
        return self.user_name


class Task(models.Model):
    """任务"""
    title = models.CharField(verbose_name='标题', max_length=64)
    detail = models.TextField(verbose_name='详细内容')

    level_cho = (
        (1, '紧急'),
        (2, '重要'),
        (3, '临时')
    )
    level = models.SmallIntegerField(verbose_name='级别', choices=level_cho, default=1)
    user = models.ForeignKey(verbose_name='负责人', to="Admin", on_delete=models.CASCADE)


class Order(models.Model):
    """订单"""
    oid = models.CharField(verbose_name='订单号', max_length=64)
    title = models.CharField(verbose_name='名称', max_length=32)
    price = models.IntegerField(verbose_name='价格')

    status_cho = (
        (1, '待支付'),
        (2, '已支付')
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_cho, default=1)

    admin = models.ForeignKey(verbose_name='管理员', to='Admin', on_delete=models.CASCADE)


class Boss(models.Model):
    """老板"""
    name = models.CharField(verbose_name='姓名', max_length=32)
    age = models.IntegerField(verbose_name='年龄')
    img = models.CharField(verbose_name='头像', max_length=128)


class City(models.Model):
    """城市"""
    name = models.CharField(verbose_name='名称', max_length=32)
    count = models.IntegerField(verbose_name='人口')
    # 本质上数据库也是CharField, 自动保存数据 - 'media/city/'
    img = models.FileField(verbose_name='logo', max_length=128, upload_to='city/')
